<template>
  <!--基本信息  -->
  <div>
    <FormPanel
      ref="formPanel"
      :list="initForm"
      :cols="2"
      :formType="'show'"
      :labelWidth="110"
      :isSubmitBtn="false"
      @formChange="formChangeHandle"
    />
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';

import { getInfoBase } from '@/api/cms-api/projectOperating/program/push';

export default {
  mixins: [dictionary],
  props: {
    //方案信息，格式： { type: type,  //页面类型
    //                  rowData: row }  //查询列表中对应方案数据
    value: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      initForm: this.initFormFun(),
      formValue: {}
    };
  },
  mounted() {

    if (this.value != null) {
      this.init();
    }
  },
  methods: {
    //加载方案基本数据
    async init() {
      
      //方案ID
      var id = this.value.rowData['projectProgramId'];
      const re = await getInfoBase(id);
      var twoDate = [];//活动周期
      
      if(re.data.projectStartDate!=null && re.data.projectEndDate!=null){
          twoDate.push(re.data.projectStartDate);//活动周期-开始
          twoDate.push(re.data.projectEndDate);//活动周期-结束
      }   

      let isFeiChu = false;//是否废除
      let programStatus = re.data['programStatus'];
      if(programStatus==25281003){//已废除
        isFeiChu = true;
        //2019-11-22 废除附件控制不能下载，修改fail属性
        this.initForm.find(item => item.fieldName === 'fileUrl').fail = true;
      }
      this.initForm.forEach(x => {
        if (x.fieldName == 'hdzq') {//初始化活动周期
          x.initialValue = twoDate;
        } else if(x.fieldName == 'fileUrl'){//处理附件，如果已废除状态，只显示不下载
            let fileList = re.data[x.fieldName];
            //2019-11-22 废除附件控制不能下载，目前不需要置空url
            // if(isFeiChu){//已废除
              
            //   if(fileList!=null && typeof(fileList)!='undefined'){
            //     fileList.map(file => {
            //       file.url = null;
            //       return file;
            //     });
            //   }
            // }
            x.initialValue = fileList;
        } else {
          x.initialValue = re.data[x.fieldName];
        }
      });
    },
    //搜索数据
    initFormFun() {
      return [
        {
          type: 'INPUT',
          label: '方案编号',
          fieldName: 'programCode',
          disabled: true,
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '方案状态',
          fieldName: 'programStatus',
          placeholder: '',
          initialValue: '',
          itemList: this.createDictList('2528'),
          disabled: true
        },
        {
          type: 'SELECT',
          label: '方案下发渠道',
          fieldName: 'programIssuedChannel',
          placeholder: '',
          initialValue: '',
          itemList: this.createDictList('2530'),
          disabled: true
        },
        {
          type: 'RANGE_DATE',
          label: '项目周期',
          fieldName: 'hdzq',
          valueFormat: 'yyyy-MM-dd', //返回数据格式
          initialValue: [],
          placeholder: '',
          style: { width: '100%' }
        },

        {
          type: 'SELECT',
          label: '是否全网下发',
          fieldName: 'isNetworkIssued',
          placeholder: '',
          initialValue: '',
          // selfCols:1,
          itemList: this.createDictList('1004')
        },
        {
          type: 'SELECT',
          label: '是否二级审核',
          fieldName: 'isSecondaryAudit',
          placeholder: '',
          initialValue: '',
          // selfCols:1,
          itemList: this.createDictList('1004')
        },
        {
          type: 'TEXT_AREA',
          label: '方案名称',
          fieldName: 'programName',
          rows: 2,
          initialValue: '',
          selfCols:2,
          placeholder: ''
        },
        {
          type: 'TEXT_AREA',
          label: '方案描述',
          fieldName: 'programDesc',
          rows: 2,
          initialValue: '',
          selfCols:2,
          placeholder: ''
        },
        {
          type: 'UPLOAD_FILE',
          label: '附件',
          fieldName: 'fileUrl',
          selfCols:2,
          fail: false,//控制是否可以下载,true：不可下载
          upload: {
            actionUrl: '/api/file/oss/upload', //上传的地址
            fixedSize: [300, 500], //剪裁尺寸
            isCalcHeight: false,
            limit: 10 //上传数量
          },
          initialValue: '',
          disabled: false
        }
      ];
    },
    formChangeHandle(val) {
      val.programIssuedChannel = '25301001'; //主机厂下发
      this.formValue = val;
    }
  }
};
</script>
